<?php

/**
 * Evento form.
 *
 * @package    form
 * @subpackage Evento
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class EventoForm extends BaseEventoForm
{
	public function configure()
	{
		parent::configure();

		$this->widgetSchema['nome'] = new sfWidgetFormInput(
			array(),
			array(
				'size' => "55",
				'maxlength' => "255"
			)
		);

		$this->widgetSchema['descricao'] = new sfWidgetFormTextarea(
			array(),
			array(
				'cols' => "55",
				'rows' => "6"
			)
		);

		$this->widgetSchema['data_evento'] = new sfWidgetFormInput(array(), array('class'=>'datepicker', 'size'=> 20));
        $this->validatorSchema['data_evento'] = new sfValidatori18nDate(array('required' => false));

      	/*
       	* Formulário embutido de mídia
       	*/
      	$form = new MidiaEventoForm(
      		null,
      		array(
				'item' => $this->getObject(),
      			'size' => 20
			)
		);

        $this->embedForm('midia', $form);

		$this->widgetSchema->setLabels(array(
			'id_evento'   => '#ID',
	      	'id_usuario'  => 'Usuário',
	      	'nome'        => 'Nome',
	      	'descricao'   => 'Descrição',
	      	'data_evento' => 'Data'
		));

		$this->validatorSchema->setOption('allow_extra_fields', true);
	}

	public function saveEmbeddedForms($con = null, $forms = null)
	{
		if (null === $forms)
		{
			$midia = $this->getValue('midia');
			$id_evento  = $this->getValue('id_evento');
			$forms = $this->embeddedForms;
			foreach ($this->embeddedForms['midia'] as $name => $form)
			{
				if (!isset($midia[$name]))
				unset($forms['midia'][$name]);
			}
		}
		parent::saveEmbeddedForms($con, $forms);

		//Criando as Thumbs
		foreach($this->getObject()->getMidia() as $midia)
		{
			$thumb   = new Midia();
			$thumb->createThumb($midia);
		}

		return;
	}
}